package it.infodea.tapestrydea.pages.demodea;

import it.infodea.tapestrydea.entities.demo.UserBean;
import it.infodea.tapestrydea.services.breadcrumb.BreadcrumbService;
import it.infodea.tapestrydea.support.annotations.PageInfo;
import it.infodea.tapestrydea.support.enumerations.SecurityGroup;

import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;

@PageInfo(category = "demo", allowedSecurityGroup=SecurityGroup.ANONYMOUS, mode = PageInfo.MODE_NORMAL)
public class BeanDemoDea {

	@Inject
	private ComponentResources resources;

	@Inject
	private BreadcrumbService breadcrumbService;

	@Persist
	private UserBean user;

	@SetupRender
	void setup() {
		breadcrumbService.addBreadcrumb(resources);
		if (user == null) {
			user = newUser(new Long(10));
		}
	}

	private UserBean newUser(Long i) {
		UserBean user = new UserBean();
		user.setFirstName("firstName_" + i);
		user.setLastName("lastName_" + i);
		user.setAge(i.intValue());
		user.setId(i);
		return user;
	}

	public UserBean getUser() {
		return user;
	}

	public Class<UserBean> getUserClass() {
		return UserBean.class;
	}
}
